/**
 *  @file QuickParser.h
 */
#ifndef _QUICKPARSER_H_
#define _QUICKPARSER_H_

#include "../../common/BaseObject.h"
#include "../../text/CFString.h"
#include "../../lang/Primitive.h"
#include "../../io/Reader.h"
#include "../../collections/StackT.h"
#include "../../collections/HashtableT.h"
#include "../JSONHandler.h"
#include "JSONTokenizer.h"

namespace cppflib
{

namespace json
{

/**
 *  Internal parser to help JSONQuickParser
 */
class QuickParser : public BaseObject
{
private:
    io::Reader *pReader;
    JSONHandler *pHandler;
    JSONTokenizer *pTokenizer;
    collections::StackCppObjT<collections::HashtableT<CFString, lang::Boolean> > *pObjectNameStack;
    bool markErrorForDupName;
private:
	QuickParser(void);
    void MarkObjectStart();
    void MarkObjectEnd();
    bool CheckNameUniquenessWithinObject(const CFString &newName);
    void NotifyErrorToHandler(JSONHandler::jsonhandlererror_t err, pcwstr_t pszFormat, ...);
    bool ParseJSONValue();
    bool __ParseJSONValue(JSONTokenizer::tokentype_t tokenType, const CFString &token);
    bool ParseJSONArray();
    bool ParseJSONObject();

public:
    QuickParser(io::Reader &reader, JSONHandler &handler, bool errorForDupName);
	virtual ~QuickParser(void);
    void StartParsing();
};

} // end of namespace json

} // end of namespace cppflib

#endif